# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=soju
pkgver=0.7.0
pkgrel=0
pkgdesc="User-friendly IRC bouncer"
url="https://soju.im/"
license="AGPL-3.0"
arch="all"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
depends="ca-certificates"
makedepends="go scdoc sqlite-dev"
subpackages="$pkgname-openrc $pkgname-doc $pkgname-utils"
source="$pkgname-$pkgver.tar.gz::https://git.sr.ht/~emersion/soju/archive/v$pkgver.tar.gz
	$pkgname.initd
	config.patch
	makefile.patch
	"
builddir="$srcdir/$pkgname-v$pkgver"

_utils="migrate-db migrate-logs znc-import"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make GOFLAGS="$GOFLAGS"

	for util in $_utils; do
		cd "$builddir"/contrib/$util
		go build -o "$builddir"/
	done
}

check() {
	go test ./...
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	# add additional docs
	install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname doc/*.md

	for util in $_utils; do
		install -Dm755 $util "$pkgdir"/usr/bin/soju-$util
	done
}

utils() {
	pkgdesc="Utilities for soju"

	for util in $_utils; do
		amove usr/bin/soju-$util
	done
}

sha512sums="
970563b873d872a99eb2f5965d6ef8f138b3f608b484173ad68a97181777199a7427b4439a2ffa2431165fd03cfe422e86257a68f937d8a24368ca239d9666da  soju-0.7.0.tar.gz
1f09a8d7eea73d5d81cdcad8a3a78fe30fc19742c13042ad2ee0448edf4108b2daf7da6fbbd4141b23fe1abd9cb931303efa6440d281a954e5d6d4956a291f7e  soju.initd
2f09bdb2efd0cd2f5f138dac7d5a4d02cfee6c46fc103c30fa70a238f322617b53ffd4b6ce6d0a8410375dd7229a68dcd6318e2b9651c5b559fff70fbca7adb3  config.patch
b647576f50ab03a90d9ab9062d97ecf050fd6e7eeba77200e05e4577733886a4ca85c7cef68d476fc611bfca41f01eecca7d3f8ce8d03431872ccb78ea2f64db  makefile.patch
"
